package org.black.phoneUtility.sms.schedule.app.fragment;

import org.black.phoneUtility.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;

public class SmsScheduleRecipientsAddRecipientsDialogFragment extends
		DialogFragment {
	public static final String TAG = SmsScheduleRecipientsAddRecipientsDialogFragment.class
			.getName();
	public static final String LOG_TAG = SmsScheduleRecipientsAddRecipientsDialogFragment.class
			.getName();

	public interface SmsScheduleRecipientsAddRecipientsDialogInterface {

		public void onChooseRecipientFromChooseFromMyContacts();

		public void onChooseRecipientsFromContactGroup();

		public void onChooseRecipientFromUserInput();
	}

	private SmsScheduleRecipientsAddRecipientsDialogInterface smsScheduleRecipientsAddRecipientsDialogInterface;

	@Override
	public void onActivityCreated(Bundle arg0) {
		super.onActivityCreated(arg0);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			smsScheduleRecipientsAddRecipientsDialogInterface = (SmsScheduleRecipientsAddRecipientsDialogInterface) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(
					activity.toString()
							+ " must implement smsScheduleRecipientsAddRecipientsDialogInterface");
		}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		super.onCreateDialog(savedInstanceState);
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setItems(R.array.sms_schedule_recipients_list_add_from,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						switch (which) {
						case 0:
							smsScheduleRecipientsAddRecipientsDialogInterface
									.onChooseRecipientFromChooseFromMyContacts();
							break;
						case 1:
							smsScheduleRecipientsAddRecipientsDialogInterface
									.onChooseRecipientsFromContactGroup();
							break;
						case 2:
							smsScheduleRecipientsAddRecipientsDialogInterface
									.onChooseRecipientFromUserInput();
							break;
						default:
							Log.e(LOG_TAG, "which not handle! which: " + which);
							break;
						}
					}
				});
		return builder.create();
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		smsScheduleRecipientsAddRecipientsDialogInterface = null;
	}

}
